package com.metis.document.parse.dialog.enums;


import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author: wuzhijun
 * @date: 2022/12/29
 */
@Getter
@AllArgsConstructor
public enum FileTypeEnum {
    PDF("pdf"),
    DOC("doc"),
    DOCX("docx"),
    WPS("wps"),
    XLS("xls"),
    XLSX("xlsx"),
    PPT("ppt"),
    PPTX("pptx"),
    TXT("txt"),
    JPEG("jpeg"),
    JPG("jpg"),
    PNG("png"),
    GIF("gif"),
    BMP("bmp"),
    TIF("tif"),
    TIFF("tiff"),
    HTML("html"),
    HTM("htm"),
    XML("xml"),
    ZIP("zip"),
    RAR("rar"),
    JSON("json"),
    MD("md"),
    ZSTD_JSON("json.zst"),
    GZIP_JSON("json.gz"),
    ;
    private final String type;

    @Nullable
    public static FileTypeEnum getFileType(@NotNull String fileName) {
        return getEnumByCode(fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase());
    }

    public String getSuffix() {
        return  "."+ type;
    }

    public static FileTypeEnum getEnumByCode(@NotNull String type) {
        return enumMap.get(type);
    }

    private static final Map<String, FileTypeEnum> enumMap = Arrays.stream(values()).collect(Collectors.toMap(FileTypeEnum::getType, Function.identity()));
}
